package com.ruoyi.controller.jpjs.bi_operate;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.jpjs.bi_importantmatter.ImportantMatterService;
import com.ruoyi.service.jpjs.bi_operate.OperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/operate")
public class OperateController extends BaseController {

    private String prefix = "jpjs/bi_operate";

    @Autowired
    private ImportantMatterService importantMatterService;

    @Autowired
    private OperateService operateService;

    @GetMapping()
    public String list(ModelMap mmp) {
        mmp.put("years",importantMatterService.getYears());
        mmp.put("months",importantMatterService.getMonths());
        return prefix + "/list";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> map) {
        return getDataTable(operateService.selectOperateList(map));
    }

    @GetMapping("/add")
    public String add(ModelMap mmp) {
        mmp.put("years",importantMatterService.getYears());
        mmp.put("months",importantMatterService.getMonths());
        mmp.put("comp", importantMatterService.getCompanyList());
        mmp.put("pro", importantMatterService.getProjectList(null));
        return prefix + "/add";
    }

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestParam Map<String, Object> map) {
        return toAjax(operateService.addOperate(map));
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmp) {
        mmp.put("operate", operateService.selectOperate(id));
        mmp.put("years",importantMatterService.getYears());
        mmp.put("months",importantMatterService.getMonths());
        mmp.put("comp", importantMatterService.getCompanyList());
        mmp.put("pro", importantMatterService.getProjectList(null));
        return prefix + "/edit";
    }

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map<String, Object> map) {
        return toAjax(operateService.editOperate(map));
    }

    @PostMapping("/remove/{id}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("id") String id) {
        return toAjax(operateService.deleteOperate(id));
    }

    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file) {
        return toAjax(operateService.importData(file));
    }

    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate() {
        return operateService.importTemplate();
    }
}
